package drive.Controller;

import drive.Model.FollowRelation;
import drive.Service.ServiceInterface.FollowRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/followrelation")
public class FollowRelationController {
    @Autowired
    private FollowRelationService followRelationService;

    // 查询所有关注关系
    @GetMapping()
    public String selectAllFollowRelations() {
        return followRelationService.findAll();
    }

//     根据followerID和followedID查询关注关系
    @GetMapping("/follower/{followerID}/followed/{followedID}")
    public String selectFollowRelationByFollowerAndFollowed(
            @PathVariable("followerID") int followerID,
            @PathVariable("followedID") int followedID) {
        return followRelationService.findByFollowerAndFollowed(followerID, followedID);
    }

    // 根据followerID查询关注关系
    @GetMapping("/follower/{followerID}")
    public String selectFollowRelationsByFollowerID(@PathVariable("followerID") int followerID) {
        return followRelationService.findByFollowerID(followerID);
    }

    // 根据followedID查询关注关系
    @GetMapping("/followed/{followedID}")
    public String selectFollowRelationsByFollowedID(@PathVariable("followedID") int followedID) {
        return followRelationService.findByFollowedID(followedID);
    }

//     新增关注关系
    @PostMapping()
    public String addFollowRelation(@RequestBody FollowRelation followRelation) {
        return followRelationService.add(followRelation);
    }

    // 更新关注关系
    @PutMapping()
    public String updateFollowRelation(@RequestBody FollowRelation followRelation) {
        return followRelationService.update(followRelation);
    }

    // 删除关注关系
    @DeleteMapping("/follower/{followerID}/followed/{followedID}")
    public String deleteFollowRelation(
            @PathVariable("followerID") int followerID,
            @PathVariable("followedID") int followedID) {
        return followRelationService.delete(followerID, followedID);
    }
}